/**
 * \file dunHeap.h
 * \brief Implementation of a int min-heap
 * \author Panos Baroudjian
**/

#ifndef DUNHEAP_H_
# define DUNHEAP_H_
# include <stdlib.h>
# include <stdio.h>

# define HSIZE(o) (2 * sizeof (size_t) + 3 * (sizeof (int) * o))
# define heapIsEmpty(h) (h->size == 0)
# define LEFT(i) (2 * i)
# define RIGHT(i) (2 * i + 1)
# define PARENT(i) (i / 2)
# define EMPTY -32767

typedef struct s_heap
{
	size_t size_max, size;
	int *som;
	float *dist;
	int *life;
	int *pos;
} *t_heap;

t_heap 	heapCreate(size_t size);

void	heapAdd(t_heap *h, int som, int life, float dist);

void	heapExtractMin(t_heap *h, int* outsom, int* outlife);

void	heapUpdate(t_heap *h, int som, int life, float dist);

void	heapPercolateDown(t_heap *h, size_t i);

void	heapPercolateUp(t_heap *h, size_t i);

void 	heapResizeBy(t_heap *h, size_t size);

void 	heapPrint(t_heap h);

void	heapFree(t_heap t);

void	swapInt(int* a, int* b);

void swapFloat(float* a, float* b);

#endif /* !DUNHEAP_H_ */
